package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;

import com.ocnyang.cartlayout.CartAdapter;
import com.ocnyang.cartlayout.viewholder.CartViewHolder;
import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.CartShopBean;
import com.scoy.honeymei.bean.GoodsOrderBean;
import com.scoy.honeymei.holder.ChildViewHolder;
import com.scoy.honeymei.holder.GroupViewHolder;
import com.scoy.honeymei.utils.GlideImgUtil;

import java.util.List;

public class CartAdapter0 extends CartAdapter<CartViewHolder> {

    public CartAdapter0(Context context, List datas) {
        super(context, datas);
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }

    public interface OnThreeClick {
        void threeClick(int pos);
    }

    OnThreeClick onThreeClick;

    public void setOnThreeClick(OnThreeClick onThreeClick) {
        this.onThreeClick = onThreeClick;
    }


    @Override
    protected CartViewHolder getNormalViewHolder(View itemView) {
        return new CartViewHolder(itemView, -1);
    }

    @Override
    protected CartViewHolder getGroupViewHolder(View itemView) {
        return (CartViewHolder) new GroupViewHolder(itemView, R.id.checkbox);
    }

    @Override
    protected CartViewHolder getChildViewHolder(View itemView) {
        return (CartViewHolder) (new ChildViewHolder(itemView, R.id.checkbox) {
            @Override
            public void onNeedCalculate() {
                if (onCheckChangeListener != null) {
                    onCheckChangeListener.onCalculateChanged(null);
                }
            }
        });
    }

    @Override
    protected int getChildItemLayout() {
        return R.layout.item_cart_item0;
    }

    @Override
    protected int getGroupItemLayout() {
        return R.layout.item_cart0;
    }

    @Override
    protected int getNormalItemLayout() {
        return R.layout.item_cart0;//无效
    }

    @Override
    public void onBindViewHolder(@NonNull CartViewHolder holder, final int position) {
        super.onBindViewHolder(holder, position);
        if (holder instanceof ChildViewHolder) {
            ChildViewHolder childViewHolder = (ChildViewHolder) holder;
            childViewHolder.cartNameTv.setText(((GoodsOrderBean) mDatas.get(position)).getName());
            childViewHolder.cartPriceTv.setText(((GoodsOrderBean) mDatas.get(position)).getMoney());
            childViewHolder.textViewNum.setText(String.valueOf(((GoodsOrderBean) mDatas.get(position)).getNumber()));
            GlideImgUtil.glidePic(mContext,((GoodsOrderBean) mDatas.get(position)).getImage(),childViewHolder.cartImgIv);

            childViewHolder.delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onOneClick != null) {
                        onOneClick.oneClick(position);
                    }
                }
            });

        } else if (holder instanceof GroupViewHolder) {
            GroupViewHolder groupViewHolder = (GroupViewHolder) holder;
            groupViewHolder.textView.setText(((CartShopBean) mDatas.get(position)).getShopname());
        }
    }
}
